import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useAvatarStore = defineStore('avatar', () => {
  const currentAvatar = ref('') // 默认头像路径
  const avatarList = ref([]) // 可选头像列表

  // 设置头像
  const setAvatar = (avatar) => {
    currentAvatar.value = avatar
    // 可选：保存到 localStorage
    localStorage.setItem('currentAvatar', avatar)
  }

  // 初始化头像（从 localStorage 读取）
  const initAvatar = () => {
    const savedAvatar = localStorage.getItem('currentAvatar')
    if (savedAvatar) {
      currentAvatar.value = savedAvatar
    }
  }

  return {
    currentAvatar,
    avatarList,
    setAvatar,
    initAvatar,
  }
})
